package com.enjoy.studyfragment.fragment;

import android.content.res.Resources;
import android.util.DisplayMetrics;

import com.enjoy.mjbaseframe.base.BaseMainFragment;
import com.enjoy.studyfragment.R;
import com.enjoy.studyfragment.bean.BottomMenuBean;
import com.flyco.tablayout.CommonTabLayout;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;

import java.util.ArrayList;
import java.util.Random;

import butterknife.BindView;
import me.yokeyword.fragmentation.SupportFragment;

/**
 * Created by Administrator on 2018/3/14.
 */

public class MainFragment extends BaseMainFragment {

    @BindView(R.id.bottomTabLayout)
    CommonTabLayout bottomTabLayout;

    public static final int FIRST = 0;
    public static final int SECOND = 1;
    private SupportFragment[] mFragments = new SupportFragment[2];
    private ArrayList<CustomTabEntity> mTabEntities = new ArrayList<>();

    @Override
    public Object setLayout() {
        return R.layout.fragment_main;
    }

    @Override
    public void init() {
        super.init();
        initFragment();
        initData();
    }

    public void initFragment(){

        SupportFragment firstFragment = findChildFragment(HomeFragment.class);
        if(firstFragment == null){
            mFragments[FIRST] = new HomeFragment();
            mFragments[SECOND] = new PersonalFragment();
            loadMultipleRootFragment(R.id.fl_tab_container, FIRST,
                    mFragments[FIRST],
                    mFragments[SECOND]);
        }
        showHideFragment(mFragments[FIRST]);
    }

    public void initData(){
        mTabEntities.add(new BottomMenuBean("首页",R.mipmap.tab_icon_xiaoxueyuan_s,R.mipmap.tab_icon_xiaoxueyuan_n));
        mTabEntities.add(new BottomMenuBean("个人",R.mipmap.tab_icon_my_s,R.mipmap.tab_icon_my_n));

        bottomTabLayout.setTabData(mTabEntities);
        bottomTabLayout.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                //选择
                showHideFragment(mFragments[position]);
            }

            @Override
            public void onTabReselect(int position) {
                //操作结束
                Random mRandom = new Random();
                bottomTabLayout.showMsg(0, mRandom.nextInt(100) + 1);
            }
        });
    }
}
